home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / Extension Shell 1.5 / Sample Extensions (1.5) / CircleMouse ][ ƒ / VBL Task.c < prev   
C/C++ Source or Header  |  1995-11-01  |  3KB  |  182 lines

  1. /*    NAME:
  2.         VBL Task.c
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.                 
  7.     DESCRIPTION:
  8.         This file contains a code resource to be installed as a VBL task.
  9.  
  10.     NOTES:
  11.         We move the mouse cursor in a tight circle when the mouse button is
  12.         down. If the Caps-Lock key is on, we have no effect.
  13.  
  14.     ___________________________________________________________________________
  15. */
  16. //=============================================================================
  17. //        Include files                                                                     
  18. //-----------------------------------------------------------------------------
  19. #include <Retrace.h>
  20. #include "A4Stuff.h"
  21. #include "SetupA4.h"
  22. #include "CM Constants.h"
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. //=============================================================================
  39. //        Private defines                                                                 
  40. //-----------------------------------------------------------------------------
  41. #define kRadius                5                // Actual radius is (1+2+...+(kRadius-1))+(kRadius/2)
  42. #define kTimeDelay            1
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. //=============================================================================
  59. //        Global Variables                                                                 
  60. //-----------------------------------------------------------------------------
  61. extern Boolean        CrsrNew        : 0x8CE;            // Low memory globals
  62. extern Point        mTemp        : 0x828;
  63. extern Point        RawMouse    : 0x82C;
  64.  
  65. Boolean                gAlreadyRan = false;
  66. int                    gVx,gVy;
  67. Boolean                gXIncreasing, gYIncreasing;
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. //=============================================================================
  84. //        Private function prototypes                             
  85. //-----------------------------------------------------------------------------
  86. void        main(VBLTask *theVBL : __D0);
  87. Boolean        CapsKeyDown(void);
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. //=============================================================================
  104. //        main : Entry point to our code resource.                                                                 
  105. //-----------------------------------------------------------------------------
  106. //        Note :    We spin the mouse cursor round in a circle, unless the Caps
  107. //                Lock key is on.
  108. //-----------------------------------------------------------------------------
  109. void main(VBLTask *theVBL : __D0)
  110. {    long                oldA4;
  111.  
  112.  
  113.     // Set up A4
  114. #ifndef powerc
  115.     oldA4 = SetCurrentA4();
  116. #endif
  117.     
  118.     
  119.     
  120.     // If we've not already been called, do our one time initialisation stuff
  121.     if (!gAlreadyRan)
  122.         {
  123.         gVx    = kRadius;
  124.         gVy    = 0;
  125.         gXIncreasing = false;
  126.         gYIncreasing = true;
  127.         gAlreadyRan    = true;
  128.         }
  129.  
  130.  
  131.     // If the mouse button is down, and the caps lock key isn't - rotate    
  132.     if (Button() && !CapsKeyDown())
  133.         {
  134.         RawMouse.h    += gVx;
  135.         mTemp.h        += gVx;
  136.         RawMouse.v    += gVy;
  137.         mTemp.v        += gVy;
  138.         
  139.         gVx += gXIncreasing ? 1 : -1;
  140.         gVy += gYIncreasing ? 1 : -1;
  141.         
  142.         gXIncreasing = (gVx == kRadius) ? false : (gVx == -kRadius) ? true : gXIncreasing;
  143.         gYIncreasing = (gVy == kRadius) ? false : (gVy == -kRadius) ? true : gYIncreasing;
  144.         
  145.         CrsrNew = true;
  146.     }
  147.     
  148.     
  149.  
  150.     // Reset our timer, and restore A4 and return
  151.     theVBL->vblCount = kTimeDelay;
  152. #ifndef powerc
  153.     SetA4(oldA4);
  154. #endif
  155. }
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171. //=============================================================================
  172. //        CapsKeyDown : Returns true if the Caps-lock key is down.                                                             
  173. //-----------------------------------------------------------------------------
  174. Boolean CapsKeyDown(void)
  175. {    unsigned char    theKeys[16];
  176.     short            theCapsKey = 57;
  177.  
  178.  
  179.     GetKeys((void *) theKeys);
  180.     return((theKeys[theCapsKey >> 3] >> (theCapsKey & 7)) & 1);
  181. }
  182.